<template>
  <el-menu
    class="el-menu-demo"
    mode="horizontal"
    text-color="#545c64"
    active-text-color="#ffd04b"
    >
    <el-menu-item  @click="exit" class="header">注销</el-menu-item>
    <el-submenu index="1" class="header">
      <template slot="title">
		<img src="../assets/img/HeadPic.png" id="headPic" alt="">
		<span id="name">{{ name }}</span>
    </template>
      <el-menu-item index="modifyEmail" @click="email">修改邮箱</el-menu-item>
      <el-menu-item index="modifyPassword" @click="password">修改密码</el-menu-item>
      <el-menu-item index="1" @click="changeRole(1)"       v-if="1!=role">切换教师</el-menu-item>
      <el-menu-item index="2" @click="changeRole(isExpert)"v-if="isExpert!=role && isExpert!=-1">切换专家</el-menu-item>
      <el-menu-item index="3" @click="changeRole(isAdmin)" v-if="isAdmin !=role && isAdmin!=-1">切换管理员</el-menu-item>
    </el-submenu>

    <el-menu-item class="header">
        <div id="tip"  @click="openDialog">
        <i class="el-icon-message"></i>
        <el-badge :value="$store.state.todoCount" class="item">待办</el-badge>
      </div>
    </el-menu-item>

    <!--教师弹窗-->
     <teacherDialog        :visible.sync="todoDialog" v-if='role==1'></teacherDialog>
    <!--院级管理员弹窗-->
     <adminDialog          :visible.sync="todoDialog" v-if='role==3 && $store.state.isAdmin==0'></adminDialog>
    <!--校级管理员弹窗-->
     <adminSchoolDialog    :visible.sync="todoDialog" v-if='role==3 && $store.state.isAdmin==1'></adminSchoolDialog>
    <!--专家弹窗-->
     <expertDialog         :visible.sync="todoDialog" v-if='role==2' ></expertDialog>

  </el-menu>
</template>
<script>
import teacherDialog  from './TodoList/teacherTodo.vue'
import adminDialog    from './TodoList/adminTodo.vue' //院级管理员
import adminSchoolDialog    from './TodoList/adminSchoolTodo.vue' //院级管理员
import expertDialog   from './TodoList/expertTodo.vue'
export default {
  components:{
    teacherDialog,adminDialog,expertDialog,adminSchoolDialog
  }
  ,
  data() {
    return {
      todoDialog:false,
      // role:this.$store.state.role,
      RecordDialog:false,
      name: this.$store.state.info.xm,
      teacherInfo:this.$store.state.info,
      dialogTipsVisible: false,
      recordData:[],
      gridData: [],
      activeName: '',
      isAdmin:'',
      isExpert:'',
      todoCount:'',
      gh:this.$store.state.info.gh
    };
  },
  created() {
    this.getTeacherDealt()
    this.getSelfIdentity()
  },
  computed:{
    role(){
       return this.$store.state.role
    }
  }
  ,
  methods: {

    //切换token方法
    changeIdentity(type){
      this.$api.teacher.changeIdentity({type:type}).then((res)=>{
        this.$store.commit("setTokenHead",res.data.data.tokenHead)
        this.$store.commit("setJsession",res.data.data.jsession_id)
        this.$store.commit("setToken",res.data.data.token)
      })
    },
    //得到自身所有用户权限数
    getSelfIdentity(){
      this.$api.teacher.getTeacherTypeByGH({gh:this.gh}).then((res)=>{
        console.log(res)
        this.isAdmin =  res.data.data.admin_id
        this.isExpert=  res.data.data.expert_id
      })
    }
    ,
    //打开弹窗
    openDialog(){
      this.getTeacherDealt()
      this.todoDialog=true
    },
    //切换角色方法
    changeRole(roleId){
        var roleTip=""
        this.changeIdentity(roleId)
        this.$api.teacher.getNavById({
          type:roleId
        }).then((response)=>{
          //刷新待办事项
          this.$store.commit('getTodoList')
          //设置角色
          this.$store.commit("setRole",roleId)
          //刷新侧边栏
          this.$store.commit("setAsideList",response.data.data);
          switch(roleId){
            case 1:
              roleTip = "教师";
              break;
            case "2":
              roleTip = "专家";
              break;
            case "3":
              roleTip = "管理员";
              break;
          }
          this.changeRoleTip(roleTip)
          this.$router.push({path:'/index'})
        })
    },
    changeRoleTip(Role){
      this.$message({
        showClose: true,
        message: "切换"+Role+"身份成功!",
        type: "success",
        center:true,
        offset:(screen.height/2)-80,
        duration:2000
      })
    },
    //刷新代办事件
    getTeacherDealt(){
      this.$store.commit('getTodoList')
      },
    email() {
      this.$router.push("/modifyEmail");
    },
    password() {
      this.$router.push("/modifyPassword");
    },
    exit() {
      localStorage.clear();
      this.$router.push("/login");
    },
  },
};
</script>
<style>
#headPic{
	height:55px;
}
.header {
  float: right;
}



#tip {
  padding-top: 18px;
  line-height: 30px;
}
#name {
  padding-left: 15px;
}
</style>
